package com.ruoyi.web.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.QuantifyProfit;
import com.ruoyi.web.service.IQuantifyProfitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/quantify")
public class QuantifyController extends BaseController {

    @Autowired
    private IQuantifyProfitService quantifyProfitService;
    @GetMapping("/showInfo")
    public String showInfo(){
        return "quantify/showInfo";
    }
    @RequestMapping("/getPersonalView")
    @ResponseBody
    public AjaxResult getPersonalView(QuantifyProfit quantifyProfit){

        SysUser user= this.getSysUser();
        quantifyProfit.setLoginName(user.getLoginName());
        List<QuantifyProfit> list=quantifyProfitService.selectQuantifyProfitSumList(quantifyProfit);
        List<String> timeList=new ArrayList<>();
        List<String> profitList=new ArrayList<>();
        list.stream().forEach(quantifyProfitTmp->{
            quantifyProfitTmp.getProfitTime();
            timeList.add(null==quantifyProfitTmp.getProfitTime()?"":DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,quantifyProfitTmp.getProfitTime()));
            profitList.add(StringUtils.isEmpty(quantifyProfitTmp.getProfitValue())?"":quantifyProfitTmp.getProfitValue());
        });
        AjaxResult result=new AjaxResult();
        result.put("timeList",timeList);
        result.put("profitList",profitList);
        return result;
    }

}
